package com.hspedu.newData.dmsxl.树.二叉搜索树的操作;

import com.hspedu.newData.dmsxl.ds.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-19 
 * @Version: 1.0
 */

public class LC669修剪二叉搜索树 {

    List<Integer> list = new ArrayList<>();

    // todo
    public TreeNode trimBST(TreeNode root, int low, int high) {
        if (root == null) return null;

        if (root.val > high){
            return trimBST(root.left,low,high);
        }
        if (root.val < low){
            return trimBST(root.right,low,high);
        }

        root.left = trimBST(root.left,low,high);
        root.right = trimBST(root.right,low,high);

        return root;

    }

    public TreeNode findNode(int[] nums,int startIndex,int endIndex){

        if (startIndex >= endIndex){
            return null;
        }

        int midIndex = startIndex + (endIndex - startIndex)/2;

        TreeNode treeNode = new TreeNode(nums[midIndex]);

        treeNode.left = findNode(nums,startIndex,midIndex);
        treeNode.right = findNode(nums,midIndex + 1,endIndex);

        return treeNode;
    }

    public void dfs(TreeNode root,int low,int high){
        if (root == null){
            return;
        }

        dfs(root.left,low,high);
        if (root.val >= low && root.val <= high){
            list.add(root.val);
        }
        dfs(root.right,low,high);
    }

}
